package com.yiding.sys.controller;

import com.yiding.sys.common.model.PageResult;
import com.yiding.sys.pojo.OrderInfo;
import com.yiding.sys.pojo.bo.OrderInfoQueryParamsBO;
import com.yiding.sys.pojo.vo.OrderDetailsVO;
import com.yiding.sys.pojo.vo.OrderListVO;
import com.yiding.sys.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * @author War horse imwarhorse@aliyun.com
 * Date: 2020/8/7
 * Description: 订单信息相关Request Handler
 */

@RestController
@RequestMapping("/info")
public class OrderInfoController {

	@Autowired
	private OrderInfoService orderInfoService;

	/*@GetMapping("/home")
	public ModelAndView managePage(ModelAndView modelAndView) {
		List<OrderInfo> orderInfoList = orderInfoService.getAll(new HashMap<>());

		// 转换为VO.
		List<OrderListVO> data = new ArrayList<>();
		for (OrderInfo orderInfo : orderInfoList) {
			OrderListVO orderListVO = new OrderListVO();
			BeanUtils.copyProperties(orderInfo, orderListVO);
			data.add(orderListVO);
		}

		modelAndView.addObject("infoList", data);
		modelAndView.setViewName("/page/main");
		return modelAndView;
	}*/

	@GetMapping("/orders")
	public PageResult<OrderListVO> getOrderList(@RequestParam Map<String, Object> params) {
		return orderInfoService.getOrderList(params);
	}

	/**
	 * 根据订单编号获取当个订单信息
	 *
	 * @param id 订单编号
	 * @return 订单对象
	 */
	@GetMapping("/order")
	OrderDetailsVO getOrderInfo(@RequestParam("id") Long id) {
		return orderInfoService.getOrderInfoById(id);
	}

	@GetMapping("/orders/query")
	PageResult<OrderListVO> queryOrderList(@RequestParam("page")Integer page,
	                                       @RequestParam("limit") Integer pageSize,
	                                       OrderInfoQueryParamsBO queryParamsBO) {
		return orderInfoService.queryOrderList(queryParamsBO, page, pageSize);
	}

}
